package com.fairytask.ui.item
{
	import com.fairytask.data.ViewObject;
	import com.fairytask.engine.components.BaseItem;
	import com.fairytask.engine.components.clip.Clip;
	import com.fairytask.engine.components.text.Label;
	import com.fairytask.engine.define.ResConfig;
	import com.fairytask.resource.StaticIni;
	import com.fairytask.tools.GoodSet;
	
	import flash.display.MovieClip;

	/**
	 * 背包item 
	 * @author zhgut
	 * 
	 */	
	public class BagItem extends BaseItem
	{
		//========================================
		public var bgMc		:MovieClip;
		public var bagImg		:Clip = new Clip;
		public var numLab		:Label = new Label();
		
		private var _configID		:int;
		private var _amount		:int;
		private var _val			:ViewObject;
		public function BagItem(val:ViewObject)
		{
			_val=val;
			data = val;
			init();
		}
		
		private function init():void
		{
			mouseChildren	=	false;
			setConfigID(_val.GetPropertiesEx("ConfigID"));
			initAmount(_val.GetProperties("Amount"));
		}
		
		public function setConfigID(val:int):void
		{
			_configID = val; 
			//=0,清空
			if(val==0 && contains(bagImg))
			{
				bagImg.clear();
				removeChild(bagImg);
				return;
			}
			if(contains(bagImg))
			{
				bagImg.clear();
				removeChild(bagImg);
			}
			
			bagImg.source = ResConfig.iconPath + StaticIni.getIniVar(_configID,"Icon") + ResConfig.iconImg;
			bagImg.width	= 50;
			bagImg.height	= 50;
			bagImg.x = 2;
			bagImg.y = 3;
			addChild(bagImg);
		}
		
		
		/**
		 * 初始化数量 
		 * @param val
		 * 
		 */
		public function initAmount(val:int):void
		{
			var frameData:Array=GoodSet.getFrameData(_configID);
			addChild(frameData[0]);
			if(val!=0)
			{
				_amount = val;
				GoodSet.setNumPos(numLab,_amount);
				addChild(numLab);
			}
		}
		
		
		/**
		 * 设置数量 
		 * @param val
		 * 
		 */
		public function set amount(val:int):void
		{
			_amount = val;
			GoodSet.setNumPos(numLab,_amount);
		}
		
		public function get amount():int
		{
			return _amount;
		}

		public function get configID():int
		{
			return _configID;
		}

		public function set configID(value:int):void
		{
			_configID = value;
		}

	}
}